package edu.hawaii.webspider;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.logging.Formatter;
import java.util.logging.LogRecord;

/**
 * Custom log output formatter for Web Spider application.
 * hh:mm:ss url Found
 * x_number of links
 * 
 * @author Lisa Chen
 * @see http://publib.boulder.ibm.com/infocenter/wasinfo/v6r0/index.jsp?topic=/
 * com.ibm.websphere.express.doc/info/exp/ae/rtrb_createformatter.html
 */
public class WebSpiderFormatter extends Formatter {

  /**
   * Inherits from Formatter.
   */
  public WebSpiderFormatter() {
    super();
  }

  /**
   * Custom web spider log format overrides Formatter.
   * 
   * @param record
   *            Default log record recorded during logging
   * @return Newly formatted log string
   * @see http://publib.boulder.ibm.com/infocenter/wasinfo/v6r0/index.jsp?topic=/
   * com.ibm.websphere.express.doc/info/exp/ae/rtrb_createformatter.html
   */
  @Override
  public String format(LogRecord record) {
    StringBuffer stringBuffer = new StringBuffer();
    SimpleDateFormat formattedDate = new SimpleDateFormat("HH:mm:ss", Locale.US);

    stringBuffer.append(formattedDate.format(new Date()));
    stringBuffer.append(' ');
    stringBuffer.append(record.getMessage());
    stringBuffer.append("\r\n");

    return stringBuffer.toString();
  }

}
